a11y: Simplify GtkProgressBarAccessible
authorEmmanuele Bassi <ebassi@gnome.org>
Wed, 27 May 2020 15:04:29 +0000 (16:04 +0100)
committerEmmanuele Bassi <ebassi@gnome.org>
Fri, 5 Jun 2020 19:35:10 +0000 (20:35 +0100)
Drop the GtkWidgetAccessibleClass.notify_gtk and the
AtkObjectClass.initialize overrides: they don't do anything relevant.

Instead, have GtkProgressBar update the accessible state when the
fraction changes.

gtk/a11y/gtkprogressbaraccessible.c
gtk/a11y/gtkprogressbaraccessibleprivate.h [new file with mode: 0644]
gtk/gtkprogressbar.c

index 62313f0ccc7c9eea37f73e9470ec0e2d11fabba2..99aaf95624491a7d02362ade1380c6d7b68aeba9 100644 (file)
 
 #include <gtk/gtk.h>
 
-#include "gtkprogressbaraccessible.h"
-
+#include "gtkprogressbaraccessibleprivate.h"
 
 static void atk_value_interface_init (AtkValueIface  *iface);
 
 G_DEFINE_TYPE_WITH_CODE (GtkProgressBarAccessible, gtk_progress_bar_accessible, GTK_TYPE_WIDGET_ACCESSIBLE,
                          G_IMPLEMENT_INTERFACE (ATK_TYPE_VALUE, atk_value_interface_init))
 
-static void
-gtk_progress_bar_accessible_initialize (AtkObject *obj,
-                                        gpointer   data)
+void
+gtk_progress_bar_accessible_update_value (GtkProgressBarAccessible *self)
 {
-  ATK_OBJECT_CLASS (gtk_progress_bar_accessible_parent_class)->initialize (obj, data);
-
-  obj->role = ATK_ROLE_PROGRESS_BAR;
-}
-
-static void
-gtk_progress_bar_accessible_notify_gtk (GObject    *obj,
-                                        GParamSpec *pspec)
-{
-  GtkWidget *widget = GTK_WIDGET (obj);
-  AtkObject *accessible;
-
-  accessible = gtk_widget_get_accessible (widget);
-
-  if (strcmp (pspec->name, "fraction") == 0)
-    g_object_notify (G_OBJECT (accessible), "accessible-value");
-  else
-    GTK_WIDGET_ACCESSIBLE_CLASS (gtk_progress_bar_accessible_parent_class)->notify_gtk (obj, pspec);
+  g_object_notify (G_OBJECT (self), "accessible-value");
 }
 
 static void
 gtk_progress_bar_accessible_class_init (GtkProgressBarAccessibleClass *klass)
 {
-  AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
-  GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
-
-  widget_class->notify_gtk = gtk_progress_bar_accessible_notify_gtk;
-
-  class->initialize = gtk_progress_bar_accessible_initialize;
 }
 
 static void
-gtk_progress_bar_accessible_init (GtkProgressBarAccessible *bar)
+gtk_progress_bar_accessible_init (GtkProgressBarAccessible *self)
 {
+  ATK_OBJECT (self)->role = ATK_ROLE_PROGRESS_BAR;
 }
 
 static void
diff --git a/gtk/a11y/gtkprogressbaraccessibleprivate.h b/gtk/a11y/gtkprogressbaraccessibleprivate.h
new file mode 100644 (file)
index 0000000..120d21c
--- /dev/null
@@ -0,0 +1,29 @@
+/* gtkprogressbaraccessibleprivate.h: Private GtkProgressBarAccessible API
+ *
+ * Copyright 2020  GNOME Foundation
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "gtkprogressbaraccessible.h"
+
+G_BEGIN_DECLS
+
+void    gtk_progress_bar_accessible_update_value        (GtkProgressBarAccessible *self);
+
+G_END_DECLS
index 53104999aaa98fb431f7f823e802202f83323f79..8490024f4b49fda3ed9f2d5db38cc4bed0099b52 100644 (file)
@@ -39,7 +39,7 @@
 #include "gtkstylecontextprivate.h"
 #include "gtkwidgetprivate.h"
 
-#include "a11y/gtkprogressbaraccessible.h"
+#include "a11y/gtkprogressbaraccessibleprivate.h"
 
 #include <string.h>
 
@@ -732,6 +732,14 @@ gtk_progress_bar_set_fraction (GtkProgressBar *pbar,
   gtk_widget_queue_allocate (pbar->trough_widget);
   update_fraction_classes (pbar);
 
+  {
+    AtkObject *accessible =
+      _gtk_widget_peek_accessible (GTK_WIDGET (pbar));
+
+    if (accessible != NULL)
+      gtk_progress_bar_accessible_update_value (GTK_PROGRESS_BAR_ACCESSIBLE (accessible));
+  }
+
   g_object_notify_by_pspec (G_OBJECT (pbar), progress_props[PROP_FRACTION]);
 }